﻿// ReSharper disable InconsistentNaming
using System.Collections.Generic;
using NEasy.Ldap.Attributes;

namespace NEasy.Ldap.Entity
{
    /// <summary>
    /// base class for all AD data transfer objects
    /// which provides the basic infrastructure
    /// for all AD entities
    /// </summary>
    public class LdapUserBase : LdapObjectBase
    {
        public LdapUserBase()
        {
            this.schemaClassName = "user";
        }

        /// <summary>
        /// sAMAccountName of the principal
        /// </summary>
        [LdapPrimaryAttribute("sAMAccountName")]
        public string SAMAccountName { get; set; }

        /// <summary>
        /// returns a list of all groups for this user
        /// </summary>
        /// <returns></returns>
        public virtual IEnumerable<LdapGroupBase> GetGroups()
        {
            var filterQuery = string.Format("(&(objectCategory=group)(member={0}))", this.DistinguishedName);


            var groups = Repository.Filter<LdapGroupBase>(filterQuery);

            return groups;
        }
    }
}
